package com.findmeastore.bc.impl;

import java.sql.Timestamp;
import java.util.List;

import com.findmeastore.bc.ICategoryBc;
import com.findmeastore.bo.CategoryBo;
import com.findmeastore.dao.ICategoryDAO;
import com.findmeastore.dto.CategoryDto;

public class CategoryBcImpl implements ICategoryBc{
	private ICategoryDAO categoryDao;
	
	public Integer getTotalCategoryCount() {
		return categoryDao.getTotalCategoryCount();
	}
	
	public List<CategoryBo> getAllCategories(){
		return categoryDao.getAllCategories();
	}
	
	public CategoryBo getCategoryById(Integer id){
		return categoryDao.getCategoryById(id);
	}
	
	public void saveCategory(CategoryDto dto){
		Integer id = dto.getId();
		CategoryBo categoryBo = null;
		if(id!=null&&id>0){//update
			categoryBo = categoryDao.getCategoryById(id);
		}else {//save
			categoryBo = new CategoryBo();
			categoryBo.setCreationTstamp(new Timestamp(System.currentTimeMillis()));
			categoryBo.setCreatedByUserId(dto.getModifiedById());
		}
		categoryBo.setName(dto.getName());
		categoryBo.setLastModifiedTstamp(new Timestamp(System.currentTimeMillis()));
		categoryBo.setLastModifiedByUserId(dto.getModifiedById());
		categoryBo.setParentCategoryId(dto.getParentCategoryId());

		categoryDao.saveCategory(categoryBo);
	}
	
	public ICategoryDAO getCategoryDao() {
		return categoryDao;
	}
	public void setCategoryDao(ICategoryDAO categoryDao) {
		this.categoryDao = categoryDao;
	}

}
